This module will allow you to select a files and then set their comment
to their version information. It is a bit more complex than the preceding
module in that we need to retrieve information from the lister and from
any selected files within that lister.
If you want to use this module on your computer, simply click on this
button and it will be copied to your DOpus5:Modules/ directory.
All you need to do to use it is to create a button in your toolbar as below:
Command Ver2Com
NOTE: Because this example is simple, there is virtually no error
checking incorporated into it.
1 /*
2 $VER: Ver2Com.dopus5 1.0 (3.8.98) D.Clarke
3 Copies file version information to comment field of file.
4 */
5 parse arg portname function source dest arguments
6 address value portname
7 options results
8 if function = 'init' then do
9 dopus command "Ver2Com" program "Ver2Com" desc "'Copies file version to comment'" 'source'
10 exit
11 end
12 lister query source display
13 if pos('version',result) = 0 then do
14 lister request '"Lister must have Version display" OK'
15 exit 5
16 end
17 lister query source path
18 path = strip(result,B,'"')
19 lister query source selfiles stem files
20 if files.count = 0 | files.count = '' | files.count = 'RESULT' then do
21 lister request '"No files selected" OK'
22 exit (5)
23 end
24 do i = 0 to files.count - 1
25 lister query source entry '"'files.i'"' stem fileinfo.
26 info = fileinfo.version||'.'fileinfo.revision' ('fileinfo.verdate')'
27 if info ~= '. ' then do
28 command wait original comment '"'path||files.i'"' '"'info'"'
29 fileinfo.comment = info
30 lister addstem source fileinfo.
31 end
32 lister select source files.i off
33 lister refresh source
34 end
35 exit
Lines:
1-4 These are just the version information for the script and a short
description of what it does.
5 Please refer to the explanation of this line given in
Example 7: Simple ARexx Module #1
6-7 Here we address the parsed portname, and tell ARexx to return results.
8 Please refer to the explanation of this line given in
Example 7: Simple ARexx Module #1
9 The dopus command is the line that actually adds your command to
the list. It breaks down as follows:
dopus command - The Opus ARexx command.
"Version2Comment" - The command name that will appear in the
command list, in quotes.
program "Ver2Com" - This tells Opus what program to call in the
DOpus5:Modules/ directory when your function
is called. The script named must have the
suffix '.dopus5', eg. the above example will
have the filename 'Ver2Com.dopus5'.
desc "'Copies file version to comment'"
- This is a short description of what your command
does. It will appear in the command list next
to your command.
'source' - This specifies to Opus that there must be a
SOURCE lister present, and for it's handle to be
sent to the function. If no SOURCE lister is
available, nothing will happen when this script
is called. Because you have indicated that you
only require the 'source' parameter, the
destination handle sent to the module will be 0.
If you are adding more than one command, you will require the relevant
number of dopus command lines. When your script is called, you
would then use 'if...then', or 'select...case' statements to action
the required function.
Since this script only adds one function, no other 'if...then'
statements are required except the one required to differentiate the
'init' function.
10 We exit because the 'init' function is finished once you have
specified your commands.
12-16 This particular example requires that the lister display has been set
to show a file's version, (see Opus manual on Environment/Lister
Display). If it hasn't, you will get a requester over the lister
informing you, and the script will then exit with a return code of 5,
(WARN).
17-18 We query the lister's path, strip any leading/trailing quotes, and
assign the variable 'path' to it.
19-23 We query the number of selected files only, (no version numbers for
directories), and instruct Opus to return the result in a compound
variable with a stem of 'files'. So you will get the following,
assuming that there are 3 selected files.
files.count = 3
files.0 = First filename
files.1 = Second filename
files.2 = Third filename
If files.count equals zero, an empty string, or the word 'RESULT', we
open a requester saying no files are selected and exit with a return
code of 5, (WARN).
24 We start a 'do' loop that will increment from 0, (first filename), to
files.count - 1, (last filename).
25 Query the lister for information on the first filename, putting the
results in to a compound variable with the stem of 'fileinfo'.
The results of this will look like the following:
fileinfo.NAME = filename
fileinfo.SIZE = size in bytes
fileinfo.TYPE = (<0>0 = dir)
fileinfo.SELECTED = 0 or 1
fileinfo.DATE = seconds since 1/1/78
fileinfo.PROTECT = protection bits (hsparwed)
fileinfo.DATSTRING = datestamp in ASCII
fileinfo.COMMENT = the filecomment (if any)
fileinfo.FILETYPE = file type (if any)
fileinfo.VERSION = version number
fileinfo.REVISION = revision number
fileinfo.VERDATE = version date (numerical dd.mm.yy format)
fileinfo.DATENUM = file date in numerical dd.mm.yy format
fileinfo.TIME = file time in hh:mm:ss 24 hour format
fileinfo.DISPLAY = any user defined display information
More information on this command can be found here .
26 We take the relevant file information and format it into a variable
'info'.
27 If 'info' equals '. ', ie. no version information available, we skip
the next statements, unselect the file, (lines 32-33), and loop to
the next filename.
28 Here we use the command command to call the 'original' Opus Comment
command, (just in case someone has replaced the original with their
own version), sending the full path and filename, and our reformatted
version information, 'info'. It will 'wait' for the command to return
before allowing the script to continue.
29-30 Now that we have provided the file with a new filecomment, we need to
update the lister display with the new information. We make the
compound variable 'fileinfo.comment' equal our new filecomment,
(info), then using the command 'lister addstem' we add the updated
entry back into our lister.
32-33 Finally, we unselect the file, then refresh the lister display so that
it displays the file unselected and with our new filecomment
information.
34 Loop back to the start of the 'do' loop.
35 Exit when we've done them all.
|